package com.lagou;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderController {
    @Autowired
    private AmqpTemplate rabbitTemplate;

    @RequestMapping("/order")
    public String creatOrder(String orderNo){
        rabbitTemplate.convertAndSend("ex.go","go",orderNo);
        return "订单已生成，等待支付。。。";
    }

    @RequestMapping("/topay")
    public String toPay(){
        String OrderInfo =(String)rabbitTemplate.receiveAndConvert("q.go");
        System.out.println(OrderInfo);

        if(OrderInfo ==null){
            String cancelOrder =(String)rabbitTemplate.receiveAndConvert("q.go.dlx");
            System.out.println(cancelOrder);
            return "已取消的订单："+cancelOrder;
        }

        return "订单："+OrderInfo+"支付成功！";
    }
}
